package com.phc.a20200511work.video;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.google.gson.Gson;
import com.phc.a20200511work.R;
import com.phc.a20200511work.interfaceBean.returndata;
import com.phc.a20200511work.javabean.webViedo;
import com.phc.a20200511work.util.httpUtil;

import java.util.ArrayList;

public class volde extends AppCompatActivity {

    private RecyclerView ActivityMainRecycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volde);
        initView();
        //拿到返回的数据
        httpUtil util = new httpUtil(this, new returndata() {
            @Override
            public void back(String data) {
                //拿到了得到了从网上拿到的url，进行解析
                ArrayList<String> title = new ArrayList<>();
                ArrayList<String> provider = new ArrayList<>();
                ArrayList<String> providerIcon = new ArrayList<>();
                ArrayList<String> cover = new ArrayList<>();
                ArrayList<String> replyCount = new ArrayList<>();
                ArrayList<String> collectionCount = new ArrayList<>();
                ArrayList<String> playUrl = new ArrayList<>();
                webViedo webViedo = new Gson().fromJson(data, webViedo.class);
                for (int i = 0; i < webViedo.getItemList().size(); i++) {
                    com.phc.a20200511work.javabean.webViedo.ItemListBean.DataBean data1
                            = webViedo.getItemList().get(i).getData();
                    if (data1.getProvider() != null ){
                        title.add(data1.getTitle());
                        provider.add(data1.getProvider().getName());
                        providerIcon.add(data1.getProvider().getIcon());
                        cover.add(data1.getCover().getFeed());
                        replyCount.add(String.valueOf(data1.getConsumption().getReplyCount()));
                        collectionCount.add(String.valueOf(data1.getConsumption().getCollectionCount()));
                        playUrl.add(data1.getPlayUrl());
                    }

                }
                //调用适配器，给定适配器参数
                MainActivityAdapter ad = new MainActivityAdapter(volde.this,title,provider,providerIcon,cover,replyCount,collectionCount,playUrl);
                //布局管理器
                LinearLayoutManager manager = new LinearLayoutManager(volde.this);
                //设置适配器
                ActivityMainRecycler.setLayoutManager(manager);
                ActivityMainRecycler.setAdapter(ad);
            }
        });
        util.execute("http://baobab.kaiyanapp.com/api/v4/tabs/selected?udid=100000&vc=168&vn=3" +
                ".3.1&deviceModel=xiaomi&first_channel=eyepetizer_baidu_market&last_channel=eyepetiz" +
                "er_baidu_market&system_version_code=20");
    }
    private void initView() {
        ActivityMainRecycler = (RecyclerView) findViewById(R.id.Activity_main_Recycler);
    }
}
